package com.yxw.live_vod_boot.controller;

import com.yxw.live_vod_boot.dto.collection_folder.*;
import com.yxw.live_vod_boot.service.OnDemandCollectionFolderService;
import com.yxw.live_vod_boot.vo.OnDemandCollectionFolderVO;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author fangmaoxin
 * &#064;date  2023年11月16日
 */
@RestController
@Api(value = "收藏-收藏夹管理", tags = "收藏-收藏夹管理")
@Slf4j
@RequestMapping("/api/collectionFolder")
public class OnDemandCollectionFolderController {

    @Autowired
    private OnDemandCollectionFolderService folderService;

    /**
     * 用户查询自己的收藏夹列表
     */
    @PostMapping("/getCollectionFolderListByUserId")
    @ApiOperation("用户查询自己的收藏夹列表")
    public BaseResult<PageVO<OnDemandCollectionFolderVO>> list(@RequestParam("userId") Long userId, @RequestBody @Validated OnDemandCollectionFolderQueryDTO dto) {
        PageVO<OnDemandCollectionFolderVO> collectionFolderList = folderService.selectCollectionFolderListByUserId(userId, dto);
        return ResultHelper.fillWithSuccess(collectionFolderList);
    }

    /**
     * 用户修改自己的收藏夹的信息
     */
    @PostMapping("/updateCollectionFolderInfoByUserId")
    @ApiOperation("用户修改自己的收藏夹的信息")
    public BaseResult updateCollectionFolderInfoByUserId(@RequestParam("userId") Long userId, @RequestBody @Validated OnDemandCollectionFolderUpdateDTO dto) {
        return BaseResult.doSuccess(folderService.updateCollectionFolderInfoByUserId(userId, dto), "收藏夹已成功修改！");
    }

    /**
     * 用户新增一个收藏夹
     */
    @PostMapping("/insertCollectionFolderInfoByUserId")
    @ApiOperation("用户新增一个收藏夹")
    public BaseResult insertCollectionFolderInfoByUserId(@RequestParam("userId") Long userId, @RequestBody @Validated OnDemandCollectionFolderAddDTO dto) {
        return BaseResult.doSuccess(folderService.insertCollectionFolderInfoByUserId(userId, dto), "收藏夹已成功添加！");
    }

    /**
     * 用户删除一个收藏夹
     */
    @PostMapping("/deleteCollectionFolderInfoByUserId")
    @ApiOperation("删除某个用户的收藏夹")
    public BaseResult deleteCollectionFolderInfoByUserId(@RequestParam("userId") Long userId, @RequestBody @Validated OnDemandCollectionFolderDeleteDTO dto) {
        return BaseResult.doSuccess(folderService.deleteCollectionFolderInfoByUserId(userId, dto), "收藏夹已成功删除！");
    }

    /**
     * 用户添加视频到收藏夹
     */
    @PostMapping("/insertVideoInToCollectionFolder")
    @ApiOperation("用户添加视频到收藏夹")
    public BaseResult insertVideoInToCollectionFolder(@RequestParam("userId") Long userId, @RequestBody @Validated OnDemandCollectionFolderInsertVideoDTO dto) {
        return BaseResult.doSuccess(folderService.insertVideoInToCollectionFolder(userId, dto), "视频已成功添加到收藏夹！");
    }

    /**
     * 用户移出收藏夹中视频
     */
    @PostMapping("/deleteVideoInCollectionFolder")
    @ApiOperation("用户移出收藏夹中视频")
    public BaseResult deleteVideoInCollectionFolder(@RequestParam("userId") Long userId, @RequestBody @Validated OnDemandCollectionFolderDeleteVideoDTO dto) {
        return BaseResult.doSuccess(folderService.deleteVideoInCollectionFolder(userId, dto), "视频已成功移出收藏夹！");
    }

    /**
     * 用户移动收藏夹中视频到其他收藏夹
     */
    @PostMapping("/moveVideoToOtherCollectionFolder")
    @ApiOperation("用户移动收藏夹中视频到其他收藏夹")
    public BaseResult moveVideoInCollectionFolder(@RequestParam("userId") Long userId, @RequestBody @Validated OnDemandCollectionFolderMoveVideoDTO dto) {
        return BaseResult.doSuccess(folderService.moveVideoToOtherCollectionFolder(userId, dto), "视频已成功移动到其他收藏夹！");
    }
}